import csv
users = [
    {"name":"张三","age":'12','username':'124124'},
    {"name":"张三","age":'12','username':'124124'},
    {"name":"张三","age":'12','username':'124124'},
]

with open("user.csv",'w',encoding='utf-8',newline='') as f:
    fn = ['name','age','username']
    writer = csv.DictWriter(f,fieldnames=fn)
    writer.writeheader()
    writer.writerows(users)
